<?php 
require_once $_SERVER["DOCUMENT_ROOT"]."/inc/core/env.inc.php";

$return["success"] = false; 
$return["html"] = null;
$return["error"] = null;

if ($_USER->login) {
		
	$sql = "SELECT * FROM ".$_DB->getPrefix()."users WHERE id = '".$_POST["idu"]."'";
	$res = $_DB->query($sql);
	
	if (count($res) > 0) {
		$return["success"] = true;
		
		//combo users
		$combo = file_get_contents($_SITE['path']['dir']['blocks']['containers']['admin'].'/admin-select-users.tag.html');
		$options = '';
		foreach ($_ADMIN->getAllUsers() as $ele) {
			if ($ele["id"] == $_POST["idu"]) {
				$select = ' selected';
			} else {
				$select = '';
			}
		
			$options .= '<option value="'.$ele["id"].'"'.$select.'>'.$ele["name"].' '.$ele["surname"].'</option>';
		}
		$combo = str_replace($_TAGS["admin-select-users-options"], $options, $combo);
		$combo = '<li>'.$combo.'</li>';
		
		//form user
		$frm = file_get_contents($_SITE['path']['dir']['blocks']['containers']['admin'].'/admin-frm-user.tag.html');
		$frm = str_replace($_TAGS["admin-frm-user-id"], $res[0]["id"], $frm);
		$frm = str_replace($_TAGS["admin-frm-user-name"], $res[0]["name"], $frm);
		$frm = str_replace($_TAGS["admin-frm-user-surname"], $res[0]["surname"], $frm);
		$frm = str_replace($_TAGS["admin-frm-user-nick"], $res[0]["nick"], $frm);
		$frm = str_replace($_TAGS["admin-frm-user-email"], $res[0]["email"], $frm);
		$frm = '<li>'.$frm.'</li>';
		
		//form modify pass
		if ($_USER->get("id") == $_POST["idu"] || $_USER->asPermission("mod_user")) {
			$frmPass = file_get_contents($_SITE['path']['dir']['blocks']['containers']['admin'].'/admin-frm-user-pass.tag.html');
			$frmPass = str_replace($_TAGS["admin-frm-user-id"], $res[0]["id"], $frmPass);
			$frmPass = str_replace($_TAGS["admin-frm-user-nick"], $res[0]["nick"], $frmPass);
			$frm .= '<li>'.$frmPass.'</li>';
		}
		
		$return["html"] = file_get_contents($_SITE['path']['dir']['blocks']['containers']['admin'].'/admin-rows.tag.html');
		$return["html"] = str_replace($_TAGS["admin-select-users"], $combo, $return['html']);
		$return["html"] = str_replace($_TAGS["admin-frm-user"], $frm, $return['html']);
		
	} else {
		$return["error"] = $_TRANSLATE->traslate('{VOCABULARY|user_not_found}', $_SESSION['LANGUAGE']);
	}
	
} else {
	$return["error"] = $_TRANSLATE->traslate('{VOCABULARY|permission_disactive}', $_SESSION['LANGUAGE']);
}

echo '('.json_encode($return).')';
?>